package org.example.leetcode;

/**
 * @author: lynn
 * @Descript:
 * @date: 2021/8/5 20:29
 * @version: 1.0
 */
public class LC55 {
    public static void main(String[] args) {
        LC55 lc=new LC55();
        int[] nums={1,0,0,3,4};
        System.out.println(lc.canJump(nums));


    }
    //fixme https://www.bilibili.com/video/BV1JM4y1K7wU
    public boolean canJump(int[] nums) {
        int maxLength=0;// 历史情况下能够到达的最远下标位置
        int n=nums.length;
        for (int i=0;i<n && i<=maxLength; i++){
            maxLength=Math.max(maxLength,nums[i]+i);
            if (maxLength>=n-1){
                return true;
            }
        }
        return false;
    }
}
